package com.weichuang.service.impl;

import com.weichuang.dao.UserDao;
import com.weichuang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

//@Component("userService")//<bean id="userService" class="com.weichuang.service.impl.UserServiceImpl" />
@Service("userService")
@Scope("singleton")
//@Scope("prototype")
public class UserServiceImpl implements UserService {
    //@Value("mysql")
    @Value("${jdbc.driver}")
    private String driver;

    //<property name="userDao" ref="userDao"/>
    @Autowired  //按照数据类型在spring容器中进行匹配，但是如果同类型的bean有多个，就不能用了
    //@Qualifier("userDao")
    //@Resource //用的不多
    private UserDao userDao;

    /*public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }*/

    @Override
    public void save() {
        System.out.println(driver);
        userDao.save();
    }

    @PostConstruct
    public void init(){
        System.out.println("init is running");
    }
}
